﻿package com.comm.db.jdbc;

 

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Hashtable;

public class MysqlAndOracleConnectionMng {
	

	
	
	 
	/**
	 * mysql 配置
	 */
	static String My_SQL_SID1 = "discuz";//  
	static String My_SQL_SID2 = "ucenter";//  
	static String My_SQL_SID3 = "uu_job";//  
	static String My_SQL_dbUser = "root";// 
	static String My_SQL_dbPassword_1_0 = "root";//  
	static String My_SQL_SIP = "172.26.6.53";
	static String My_SQL_port = "3306";

	static String My_SQL_url_discuz = "jdbc:mysql://" + My_SQL_SIP + ":" + My_SQL_port	+ "/" + My_SQL_SID1;//jdbc:mysql://172.26.6.57:3306/discuz
	static String My_SQL_url_ucenter = "jdbc:mysql://" + My_SQL_SIP + ":" + My_SQL_port	+ "/" + My_SQL_SID2;//jdbc:mysql://172.26.6.57:3306/discuz
	static String My_SQL_url_dbtest = "jdbc:mysql://" + My_SQL_SIP + ":" + My_SQL_port	+ "/" + My_SQL_SID3+"?characterEncoding=gbk";//jdbc:mysql://172.26.6.57:3306/discuz
	
	
	static {

		String My_SQL_DriverString = "com.mysql.jdbc.Driver";
		 
		try {
		 
			Class.forName(My_SQL_DriverString).newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("加载驱动出错");
		}
		

	}
	
public   static Hashtable<String,Connection> hashTable=new Hashtable();
/**
 * 取得 mysql connection
 * @param mysql
 * @return
 */
    public static int initcoutn1=0;
    public static int initcoutn2=0;
    public static int initcoutn3=0;
	public static synchronized Connection getConnection(String dbname) {
		
		
		if("discuz".equals(dbname)){
			Connection _conn=  getConn(MysqlAndOracleConnectionMng.My_SQL_url_discuz, MysqlAndOracleConnectionMng.My_SQL_dbUser,
								MysqlAndOracleConnectionMng.My_SQL_dbPassword_1_0);
			 return _conn;
		}else if("uu_job".equals(dbname)){

			Connection _conn=  getConn(MysqlAndOracleConnectionMng.My_SQL_url_dbtest, MysqlAndOracleConnectionMng.My_SQL_dbUser,
									MysqlAndOracleConnectionMng.My_SQL_dbPassword_1_0);
			 return _conn;
		
		}
		else{
			Connection _conn=  getConn(MysqlAndOracleConnectionMng.My_SQL_url_ucenter, MysqlAndOracleConnectionMng.My_SQL_dbUser,
									MysqlAndOracleConnectionMng.My_SQL_dbPassword_1_0);
			 return _conn;
		}
	 
	}
	private static synchronized Connection getConn(String jdbcurl,String username,String pw){
		try {
			Connection _conn = DriverManager.getConnection(jdbcurl, username,
					pw);
			return _conn;
		} catch (SQLException e) {
			 
			e.printStackTrace();
			System.out.println("建立mysql连接失败");
		}
		return null;
	}
	

	public static void main(String[] arg) throws SQLException { 
	 
		Connection mysql_conn = null;
		
		mysql_conn=MysqlAndOracleConnectionMng.getConnection("uu_job");
		 
		
		System.out.println(mysql_conn.getMetaData());
	 
 
		
		
		Statement mysql_stat;
		ResultSet mysql_rs;
		CallableStatement proc = null;
		String MYSQL_QUERY="select * from t_job";

		PreparedStatement stat=mysql_conn.prepareStatement(MYSQL_QUERY);
		mysql_rs=stat.executeQuery();
		
		
		while(mysql_rs.next()){
			
			proc=null;
			
			int uid=(Integer)mysql_rs.getObject(1);
			int companyid=(Integer)mysql_rs.getObject(2);
			String jobname=(String)mysql_rs.getObject(3);
			 
			System.out.println(uid);
			System.out.println(companyid);
			System.out.println(jobname);
			System.out.println("插入成功");
			
			//插入成功后，删除旧记录
	 System.out.println("插入成功");
	 
			

		}
		
		
 }
	
	
}
